package com.graducationdesign.springboot.controller.Admin;

import com.graducationdesign.springboot.entities.Administrator.GraducationDesignListMoudle.VoiceMessage;
import com.graducationdesign.springboot.mapper.VoiceMessageMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;
import java.util.Map;

/**
 * @author Mr.zhneg
 * @create 2019-11-24-11:22
 */
@Controller
public class VoiceMessageController {

    //    这LoggerFactory是一个实用程序类，用于为各种日志记录API生成Logger，尤其是对于log4j，logback和JDK 1.4日志记录

    //org.slf4j.Logger接口是SLF4J API的主要用户入口点。期望通过该接口的具体实现进行日志记录。
    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    VoiceMessageMapper voiceMessageMapper;

    //查看消息管理界面，并且可以查询消息的发送者

    @GetMapping("/voiceMessage")
    public String list(VoiceMessage voiceMessage, Map<String, Object> map) {

        logger.info("消息查询" + voiceMessage);

        List<VoiceMessage> voiceMessages = voiceMessageMapper.getAllMessage(voiceMessage);
        logger.info("查询操作：消息查询结果。。。" + voiceMessages);
        map.put("voicemessage", voiceMessages);
        map.put("sendname", voiceMessage.getSendname());

        return "Administrator/graduationDesignInformationMoudle/voiceMessageManagement";
    }

    //删除学生信息
    @DeleteMapping("/voiceMessage/{sendname}")
    public String delete(@PathVariable("sendname") String sendname){

        logger.info("删除操作：删除发送者为"+sendname+"的学生");
        voiceMessageMapper.deleteMessageBySendname(sendname);
        return "redirect:/voiceMessage";

    }
}
